package org.redmagic.common;

import java.io.Serializable;
import java.util.Set;

import com.fasterxml.jackson.annotation.JsonProperty;

public class MagicRequest implements Serializable {

	private static final long serialVersionUID = -4497500630294023672L;
	
	private final Hierarchy hierarchy;
	private final Set<String> placeholders;
	private final String group;
	
	public MagicRequest(@JsonProperty("hierarchy") Hierarchy hierarchy, 
						@JsonProperty("placeholders") Set<String> placeholders,
						@JsonProperty("group") String group) {
		this.hierarchy = hierarchy;
		this.placeholders = placeholders;
		this.group = group;
	}
	
	public Hierarchy getHierarchy() {
		return hierarchy;
	}

	public Set<String> getPlaceholders() {
		return placeholders;
	}
	
	public String getGroup() {
		return group;
	}

	@Override
	public String toString() {
		return "Hierarchy: " + hierarchy + "\nPlaceholders: " + placeholders + "\nGroup: " + group;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((group == null) ? 0 : group.hashCode());
		result = prime * result
				+ ((hierarchy == null) ? 0 : hierarchy.hashCode());
		result = prime * result
				+ ((placeholders == null) ? 0 : placeholders.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		MagicRequest other = (MagicRequest) obj;
		if (group == null) {
			if (other.group != null)
				return false;
		} else if (!group.equals(other.group))
			return false;
		if (hierarchy == null) {
			if (other.hierarchy != null)
				return false;
		} else if (!hierarchy.equals(other.hierarchy))
			return false;
		if (placeholders == null) {
			if (other.placeholders != null)
				return false;
		} else if (!placeholders.equals(other.placeholders))
			return false;
		return true;
	}
	
}
